// import request from '@/utils/request';

// 🦜 : let's add our mocks here...
const tokens = {admin: {token: 'admin-token'}, editor: {token: 'editor-token'}};

const users = {
    'admin-token': {roles: ['admin'], introduction: 'I am a super administrator',
                    // avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
                    avatar: '/black.jpeg',
                    name: 'Super Admin'},
    'editor-token': {
        roles: ['editor'], introduction: 'I am an editor',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', name: 'Normal Editor'}
};


export function login(data) {
    // let o = request({url: '/dirty/user/login', method: 'post', data});
    const {username} = data;
    const token = tokens[username];
    let o = new Promise((Y, N) => {
        setTimeout(() => {
            if (!token) {
                Y({code: 1, message: 'Account and password are incorrect.'});
            }
            let r = {code: 0, data: token};
            Y(r);
        }, 500);
    });
    console.log('login with', o);
    return o;
}

export function getInfo(token) {
    // return request({url: '/dirty/user/info', method: 'get', params: { token }});
    const info = users[token];
    if (!info)
        return {code: 1, message: 'Login failed, unable to get user details.'};

    let o = new Promise((Y, N) => {
        setTimeout(() => {
            let r = {code: 0, data: info};
            Y(r);
        }, 500);
    });
    return o;
}

export function logout(token) {
  // return request({url: '/dirty/user/logout', method: 'post', params: { token }});
    return new Promise((Y, N) => {Y({code: 0, data: 'success'});});
}
